home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / bbs / Hydra11s.lha / HBBS / Source / Doors_System / AddDIZToList / Main.C < prev    next >
C/C++ Source or Header  |  1996-10-31  |  7KB  |  290 lines

  1. /*
  2.  
  3.   AddDIZToList
  4.   ============
  5.  
  6.   Adds a .DIZ to a file list
  7.  
  8.  
  9.   Options
  10.   =======
  11.  
  12.     N_ND->ActiveDoor->SystemOptions
  13.     -------------------------------
  14.  
  15.     none
  16.  
  17.     Door Options (Command Line)
  18.     ---------------------------
  19.  
  20. 2   <confnum> | "BAD" | "HOLD" | "SYSOP"
  21.  
  22. 3   <diz_file>
  23.  
  24. 4   <filename>
  25.  
  26. */
  27.  
  28.  
  29. #include <exec/types.h>
  30. #include <exec/memory.h>
  31. #include <dos/dos.h>
  32. #include <clib/exec_protos.h>
  33. #include <clib/dos_protos.h>
  34. #include <clib/alib_protos.h>
  35.  
  36. #include <stdlib.h>
  37. #include <string.h>
  38. #include <stdio.h>
  39. #include <ctype.h>
  40. #include <time.h>
  41.  
  42.  
  43. #ifdef __SASC
  44. int CXBRK(void) { return(0); }
  45. int _CXBRK(void) { return(0); }
  46. void chkabort(void) {}
  47. #endif
  48.  
  49. #include <HBBS/ANSI_Codes.h>
  50. #include <HBBS/Defines.h>
  51. #include <HBBS/types.h>
  52. #include <HBBS/structures.h>
  53. #include <HBBS/hbbscommon_protos.h>
  54. #include <HBBS/hbbscommon_pragmas.h>
  55. #include <HBBS/Hbbsnode_protos.h>
  56. #include <HBBS/Hbbsnode_pragmas.h>
  57. #include <HBBS/release.h>
  58. char *versionstr="$VER: AddDIZToList "RELEASE_STR;
  59.  
  60. struct Library *HBBSCommonBase=NULL;
  61. struct Library *HBBSNodeBase=NULL;
  62.  
  63. struct BBSGlobalData *BBSGlobal=NULL;
  64. struct NodeData *N_ND=NULL;
  65. int N_NodeNum=-1;
  66. char outstr[1024]; // temp string for displaying text..
  67.  
  68.   struct List *FileID=NULL;
  69.   UBYTE *filename=NULL;
  70.  
  71. static VOID cleanup(ULONG num)
  72. {
  73.   if (HBBSNodeBase)
  74.   {
  75.     HBBS_CleanUpDoor();
  76.     CloseLibrary (HBBSNodeBase);
  77.   }
  78.  
  79.   if (HBBSCommonBase)
  80.   {
  81.     HBBS_CleanUpCommon();
  82.     CloseLibrary (HBBSCommonBase);
  83.   }
  84.  
  85.   if (num) printf("Door Error = %d\n",num);
  86.  
  87.   exit(0);
  88. }
  89.  
  90. static VOID init(char *name)
  91. {
  92.   if(!(HBBSCommonBase = OpenLibrary("HBBSCommon.library",0)))
  93.   {
  94.     cleanup(1);
  95.   }
  96.  
  97.   if (!(HBBS_InitCommon()))
  98.   {
  99.     cleanup(2);
  100.   }
  101.  
  102.   if(!(HBBSNodeBase = OpenLibrary("HBBSNode.library",0)))
  103.   {
  104.     cleanup(3);
  105.   }
  106.  
  107.   if (!(HBBS_InitDoor(N_NodeNum,name)))
  108.   {
  109.     cleanup(4);
  110.   }
  111.   SetProgramName(name);
  112. }
  113.  
  114. /*
  115.   File Format of List file (as of 03-JAN-1995)
  116.   --------------------------------------------
  117.  
  118. F FileName.EXT 99999999 DD-MMM-YYYY |-File_ID------45 chars---------------------|
  119. T                          HH:MM:SS |-More ID-----------------------------------|
  120. N                          Node XXX |-More ID-----------------------------------|
  121. I                                   |-More ID-----------------------------------|
  122. U                                   Uploader Name/Sent bY string
  123. C                                   Comments, Not Displayed By File Lister
  124. C                                   Programs Unless Specified by the sysop...
  125. X                                   Nuker Comments
  126.  
  127. */
  128.  
  129. void AddDIZ(int argc,char *argv[])
  130. {
  131.   BPTR FH=NULL,FL;
  132.   struct FileInfoBlock FB;
  133.   LONG count=0;
  134.   char c;
  135.   struct Node *node;
  136.   char datestr[LEN_DATESTR];
  137.   char timestr[LEN_TIMESTR];
  138.   strcpy(outstr,N_ND->NodeSettings.NodePlayPen);
  139.   strcat(outstr,argv[4]);
  140.  
  141.   if (FL=Lock(outstr,ACCESS_READ))
  142.   {
  143.     if (Examine(FL,&FB))
  144.     {
  145.       if (FH=Open(filename,MODE_OLDFILE))
  146.       {
  147.         Seek(FH,-1,OFFSET_END);
  148.         Read(FH,&c,1);
  149.         if (c!='\n') Write(FH,"\n",1);
  150.       }
  151.       else
  152.       {
  153.         FH=Open(filename,MODE_NEWFILE);
  154.       }
  155.       if (FH)
  156.       {
  157.         for (node = FileID->lh_Head ; count<N_ND->MaxDIZLines && node->ln_Succ ; node =node->ln_Succ,count ++)
  158.         {
  159.           switch(count)
  160.           {
  161.             case 0:
  162.               HBBS_GetDate(datestr);
  163.               sprintf(outstr,"F %-12s %8ld %s %s",argv[4],FB.fib_Size,datestr,node->ln_Name);
  164.               break;
  165.             case 1:
  166.               HBBS_GetTime(timestr);
  167.               sprintf(outstr,"T                          %s %s",timestr,node->ln_Name);
  168.               break;
  169.             case 2:
  170.               sprintf(outstr,"N                          Node %3d %s",N_NodeNum,node->ln_Name);
  171.               break;
  172.             default: // 3 or more..
  173.               sprintf(outstr,"I                                   %s",node->ln_Name);
  174.               break;
  175.           }
  176.           strcat(outstr,"\n");
  177.           Write(FH,outstr,strlen(outstr));
  178.         }
  179.         if (N_ND->User.CallData.SentBy[0]) // blank sentby ?
  180.         {
  181.           DOOR_WriteText(ANSI_RESET ANSI_FG_BLUE ANSI_BOLD "Adding Sentby string!\r\n");
  182.           sprintf(outstr,"U                                   %s",N_ND->User.CallData.SentBy);
  183.           Write(FH,outstr,strlen(outstr));
  184.         }
  185.         Close(FH);
  186.       }
  187.     }
  188.     UnLock(FL);
  189.   }
  190. }
  191.  
  192.  
  193. void DoorMain(int argc,char *argv[])
  194. {
  195.   LONG ConfNum,loop;
  196.   struct ConfData *Conf;
  197.  
  198.   if (argc>=4)
  199.   {
  200.  
  201.     if (FileID=HBBS_LoadFile(argv[3]))
  202.     {
  203.       if (HBBS_NodesInList(FileID))
  204.       {
  205.         if ((stricmp(argv[2],"HOLD")==0) || (stricmp(argv[2],"SYSOP")==0))
  206.         {
  207.           if (N_ND->CurrentConf)
  208.           {
  209.             filename=N_ND->CurrentConf->HoldFileList;
  210.           }
  211.         }
  212.         else
  213.         {
  214.           if (stricmp(argv[2],"BAD")==0)
  215.           {
  216.             if (N_ND->CurrentConf)
  217.             {
  218.               filename=N_ND->CurrentConf->BadFileList;
  219.             }
  220.           }
  221.           else
  222.           {
  223.             // first we find the conference number.
  224.             if (ConfNum=atoi(argv[2]))
  225.             {
  226.               if (ConfNum>=1 && ConfNum<=BBSGlobal->Conferences) // Valid Conference ?
  227.               {
  228.                 // now we get the data structure that points to the conference data
  229.                 Conf=(struct ConfData *)GetNode(BBSGlobal->ConfList,ConfNum-1);
  230.  
  231.                 if (Conf->FileList)
  232.                 {
  233.                   // then we get a the filename of the list we want to add our .DIZ to
  234.                   // which is the last items in the linked list of file lists..
  235.  
  236.                   filename=HBBS_ListName(Conf->FileList,Conf->FileLists-1);
  237.  
  238.                 }
  239.               }
  240.             }
  241.           }
  242.         }
  243.         if (filename)
  244.         {
  245.           DOOR_WriteText(ANSI_RESET ANSI_FG_CYAN ANSI_BOLD "Adding Diz To: " ANSI_ITALIC);
  246.           DOOR_WriteText(filename);
  247.           DOOR_WriteText(ANSI_RESET "\r\n");
  248.  
  249.           AddDIZ(argc,argv);
  250.         }
  251.       }
  252.       else
  253.       {
  254.         DOOR_WriteText("Empty File ID, not adding!\r\n");
  255.       }
  256.       FreeStrList(FileID);
  257.     }
  258.   }
  259.   else
  260.   {
  261.     strcpy(outstr,"Invalid Parameters for AddDIZtoList\n");
  262.     for (loop=0;loop<argc;loop++)
  263.     {
  264.       strcat(outstr,argv[loop]);
  265.       strcat(outstr," ");
  266.     }
  267.     DOOR_SysopText(outstr);
  268.     HBBS_AddToCallersLog(outstr);
  269.   }
  270. }
  271.  
  272. int main(int argc,char *argv[])
  273. {
  274.   if (sscanf(argv[1],"%d",&N_NodeNum)==0)
  275.   {
  276.     printf("Invalid/No Paramaters for door!\n");
  277.     exit (20);
  278.   }
  279.   init("AddDIZToList");
  280.  
  281.   if (BBSGlobal=HBBS_GimmeBBS())
  282.   {
  283.     if (N_ND=HBBS_NodeDataPtr(N_NodeNum)) // this should not fail in normal circumstances..
  284.     {
  285.       DoorMain(argc,argv);
  286.     }
  287.   }
  288.   cleanup(0);
  289. }
  290.